package com.hmall.user.interceptor;

import com.hmall.user.context.BaseContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Slf4j
public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
        String userID = request.getHeader("authorization");
        log.info("用户服务。。。登录ID:{}", userID);

        if(null != userID) {
            BaseContext.setCurrentId(Long.valueOf(userID));
            return true;
        }

        return false;
    }
}
